package com.example.config;

import com.example.constants.Constants;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQLengthConfig {
    //交换机名称
    private String lengthFanoutExchangeName = Constants.MY_LENGTH_FANOUT_EXCHANGE;

    //队列名称
    private String lengthQueueName = Constants.MY_LENGTH_QUEUE_NAME;

    @Bean
    public FanoutExchange lengthFanoutExchangeName(){
        FanoutExchange fanoutExchange = new FanoutExchange(lengthFanoutExchangeName);
        return fanoutExchange;
    }

    @Bean
    public Queue lengthQueueName(){
        Queue queue = new Queue(lengthQueueName);
        /**
         * 添加队列的参数
         */
        queue.addArgument("x-max-length",10);
        /**
         * 绑定死信队列
         */
        queue.addArgument("x-dead-letter-exchange",Constants.MY_DLX_DIRECT_EXCHANGE);
        queue.addArgument("x-dead-letter-routing-key","dlx");
        return queue;
    }

    @Bean
    public Binding binding4(Queue lengthQueueName,FanoutExchange lengthFanoutExchangeName){
        //将队列绑定到交换机
        Binding binding = BindingBuilder.bind(lengthQueueName).to(lengthFanoutExchangeName);
        return binding;
    }
}